package snail.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author Johan
 */
public class User implements Serializable {

    private int userId;
    private boolean isAdmin;
    private String firstName;
    private String lastName;
    private String email;
    private String password;
    private String address;
    private String postAddress;
    private Date registerDate;
    private Set bids = new HashSet();
    private Set articles = new HashSet();
    private Set userRatings = new HashSet();
    private Set watchedArticles = new HashSet();
    private boolean confirmed;

    public float getUserRatingsFormatted() {
        float sum = getUserRatings().size();
        if (sum == 0) {
            return -1;
        } else {
            return getNrPositiveRatings() / sum * 100;
        }
    }

    public float getNrPositiveRatings() {
        float nrPositive = 0;
        for (UserRating rating : getUserRatings()) {
            if (rating.isIsPositive()) {
                nrPositive++;
            }
        }

        return nrPositive;
    }

    public HashSet<Article> getUserArticleRatings() {
        HashSet<Article> hs = new HashSet<Article>();
        for (UserRating a : getUserRatings()) {
            hs.add(a.getArticle());
        }
        return hs;
    }

    public boolean isConfirmed() {
        return confirmed;
    }

    public void setConfirmed(boolean confirmed) {
        this.confirmed = confirmed;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Set getArticles() {
        return articles;
    }

    public void setArticles(Set articles) {
        this.articles = articles;
    }

    public Set getBids() {
        return bids;
    }

    public void setBids(Set bids) {
        this.bids = bids;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public boolean isAdmin() {
        return isAdmin;
    }

    public boolean isIsAdmin() {
        return isAdmin;
    }

    public void setIsAdmin(boolean isAdmin) {
        this.isAdmin = isAdmin;
    }

    public void setAdmin(boolean isAdmin) {
        this.isAdmin = isAdmin;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPostAddress() {
        return postAddress;
    }

    public void setPostAddress(String postAddress) {
        this.postAddress = postAddress;
    }

    public Date getRegisterDate() {
        return registerDate;
    }

    public void setRegisterDate(Date registerDate) {
        this.registerDate = registerDate;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public Set<UserRating> getUserRatings() {
        return userRatings;
    }

    public void setUserRatings(Set userRatings) {
        this.userRatings = userRatings;
    }

    public Set getWatchedArticles() {
        return watchedArticles;
    }

    public void setWatchedArticles(Set watchedArticles) {
        this.watchedArticles = watchedArticles;
    }
}
